package pool;

import java.util.Date;
import java.util.concurrent.*;

public class ScheduleThreadPoolTest1 {

    public static void main(String[] args) {
        System.out.println("创建任务时间："+new Date().toLocaleString());
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        // 建立一个延迟任务
        ScheduledFuture<String> futrue = executor.schedule(new MyTask_1("haha"), 15, TimeUnit.SECONDS);
        try {
            System.out.println(futrue.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        executor.shutdown();

        long second = getSecond(new Date("2022/3/10 01:25:00"));
        System.out.println(second);
    }

    private static long getSecond(Date date) {
        long futureTime = date.getTime();
        long now = new Date().getTime();
        long c = (futureTime-now)/1000;
        return c;
        
    }
}

class MyTask_1 implements Callable<String>{

    private String taskName;

    public MyTask_1(String taskName) {
        this.taskName = taskName;
    }

    @Override
    public String call() throws Exception {
        System.out.println("任务开始执行时间："+new Date());
        return taskName;
    }
}
